var member_id = '';
document.addEventListener('plusready',function(){
	member_id = plus.storage.getItem('id');	
	store_ids = plus.storage.getItem('store_id');
	var ws = plus.webview.currentWebview();
	var cart_id = ws.cart_id;
	var store_id = ws.store_id;
	var cart_name = ws.cart_name;
	$('.mui-title').text(cart_name);
	if(!store_id){
		store_id = store_ids;
	}
//	console.log(apiRoot+"?act=index&op=mobile"+cart_id+'--'+store_id);
	$.ajax({ 
		type:"post", 
		url:apiRoot+"?act=index&op=mobile",
		data:{cart_id:cart_id,store_id:store_id},
		dataType:"json",
		success:function(data){ 
//			console.log(JSON.stringify(data));
			if(data.length > 0){
				var html = '';
				var html2 = '';   
				$.each(data, function(k, v) {
					html += '<a class="mui-control-item '+(k==0?'mui-active':'')+'" href="#content'+ k +'">'+v.gc_name+'</a>';
					html2 += '<div id="content'+ k +'" class="mui-control-content '+(k==0?'mui-active':'')+'"'+
									'<div class="nd-mall-indexIm">';
						$.each(v.goods_details, function(key, value) {  
							html2 += '<ul class="mui-table-view Hot" data-id="'+ value.goods_id +'" data-did="'+ value.store_id +'">'+
										'<li class="mui-table-view-cell frien_img">'+
											'<div class="home_top">'+
												'<img src="'+ pics + value.store_id + '/' + value.goods_image +'">'+
											'</div>'+
											'<div class="frien_bq">	'+																			
												'<div class="mui-ellipsis-2">'+ value.goods_name +'</div>	'+														
												'<b class="red">￥'+ value.goods_price +'<span class="mui-h6 mui-pull-right">销量：'+ value.goods_salenum +'</span></b>'+													
											'</div>'+
										'</li>'+
									  '</ul>';
						});
						html2 += '</div>'+
								'</div>';
				});   
				$('#segmentedControls').html(html);
				$('#segmentedControlContents').html(html2);	
			}else{
				toast('没有该类数据！');
			}
			//详情 
			$('.Hot').unbind('tap');
			$('.Hot').on('tap',function(){
				var _this = $(this);
				var goodsid = _this.attr('data-id');
				var store_id = _this.attr('data-did');
				var nwaiting = plus.nativeUI.showWaiting();//显示原生等待框
				var webviewContent= plus.webview.create('./goods_details.html','goods_details.html',{},{goodsid:goodsid,store_id:store_id});//后台创建webview并打开show.html
				webviewContent.addEventListener("loaded", function() { //注册新webview的载入完成事件
			        nwaiting.close(); //新webview的载入完毕后关闭等待框
			        webviewContent.show("slide-in-right",500); //把新webview窗体显示出来，显示动画效果为速度200毫秒的右侧移入动画
			    }, false);
			})
		},  
		error:function(e){
			console.log(JSON.stringify(e));
			toast('连接失败！');
		}
	});
},false);